package com.icxcc.generator.exception;

import com.icxcc.common.framework.exception.ICXException;
import com.icxcc.common.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ICXExceptionHandler {

    @ExceptionHandler(ICXException.class)
    public R handleICXException(ICXException e){
        return R.failed(e.getCode(),e.getMsg());
    }

    @ExceptionHandler(DuplicateKeyException.class)
    public R handleDuplicateKeyException(DuplicateKeyException e){
        log.error(e.getMessage());
        return R.failed(1000, "");
    }

    @ExceptionHandler(AuthenticationException.class)
    public R handleAuthorizationException(AuthenticationException e){
        log.error(e.getMessage());
        return R.failed(1000, "");
    }

    @ExceptionHandler(Exception.class)
    public R handleException(Exception e){
        log.error(e.getMessage());
        return R.failed(1000,"");
    }
}
